import java.util.HashSet;
import java.util.Iterator;

public class HashSetTest {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        hashSet.add("aaa");
        hashSet.add("bbb");
        hashSet.add("ccc");
        hashSet.add("ccc");
        hashSet.add("ccc");
        hashSet.add("ddd");

        //通过遍历看出，是无序且不重复的
        Iterator it = hashSet.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

        HashSet hashSet_2 = new HashSet();
        hashSet_2.add("111");
        hashSet_2.add("222");
        hashSet_2.add("333");
        hashSet.addAll(hashSet_2);

        //通过遍历看出，是无序且不重复的
        Iterator it_2 = hashSet.iterator();
        while (it_2.hasNext()){
            System.out.println(it_2.next());
        }

        getAllPerson();
    }

    public static void getAllPerson(){
        HashSet hashSet = new HashSet();
        hashSet.add(new Person("aaa",21));
        hashSet.add(new Person("bbb",22));
        hashSet.add(new Person("ccc",23));
        hashSet.add(new Person("bbb",22));
        Iterator it = hashSet.iterator();
        while (it.hasNext()){
            Person p = (Person) it.next();
            System.out.println(p+":"+p.getName()+":"+p.getAge()+":"+p.hashCode());
        }
    }

}
